import { noAuthRouters } from "./config";

export default function (e: any) {
    console.log(e, "handlerLaunch");
    const url = e.path.split("?")[0];
    handlerUrl(url);
}

export function handlerUrl(url: string): boolean {
    const token = uni.getStorageSync("TOKEN");
    //获取当前页面路径（即url去掉"?"和"?"后的参数）
    console.log(url, "|-调用前拦截,router index url");
    console.log(
        token,
        "|-调用前拦截,如果token为空就拦截，不允许访问router index token"
    );
    console.log(noAuthRouters.includes(url));
    const isAuth = false// !noAuthRouters.includes(url) && !token;
    // if (!noAuthRouters.includes(url) && !token) {
    if (isAuth) {
        uni.showToast({
            title: "请先登录",
            icon: "none",
        });
        // uni.navigateTo({
        //     url: "/pages/login/login",
        // });
    }
    return !isAuth;
}
